package org.andao.commons.lucene.core;

import org.andao.commons.lucene.exception.LuceneQueryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



/**
 * LuceneServer工厂
 * 
 * @author Seewo Software - Vick.liu (liuguanglin@cvte.cn)
 * 
 */
public class LuceneServerFactory {

	private static Logger logger = LoggerFactory.getLogger(LuceneServerFactory.class);

	/**
	 * luceneServer
	 */
	public static Object luceneServer;

	/**
	 * 获取server
	 * 
	 * @param context
	 *            luceneServer上下文
	 * @return
	 * @throws LuceneQueryException
	 */
	public static Object getServer(LuceneServerContext context) throws LuceneQueryException {
		// TODO @vick Singleton should be used here.With spring context?
		if (luceneServer == null) {
			try {
				luceneServer = context.getServer();
			} catch (Exception e) {
				logger.info("获取全文检索服务器出错：" + e.getMessage());
				throw new LuceneQueryException("获取全文检索服务器出错：" + e);
			}
		}

		return luceneServer;
	}

}
